<?php $this->load->view('header/admin'); ?>
<div id="main">
    <div class="container">
        <div class="span-17 colborder" id="content">
        <?php if (isset($messages)) echo $messages; ?>
            <h3 class="caps">People</h3>
            <div class="span-17 box last">
                <p>We have <?php echo count($people); ?> registered users in the system.</p>
            </div>
	        <?php if ($people): ?>
	           <div id="info" class="span-17 last">
                    <div class="box span-5">
                        <div id="search-form">
                                <label for="search">Type a Name or part</label>
                                <input type="text" id="name_autocomplete" name="name" autocomplete="off" />
                            <p>[ <a id="modify-link" href="#">Modify</a> ]</p>
                        </div>
                    </div>
                    <div id="person-details" class="box span-11 last" style="">
	                    <dl class="span-5">
                            <dt class="caps">CIVL ID: </dt> 
                            <dd id="person-id">&nbsp;</dd>
	                        <dt class="caps">Name: </dt> 
	                        <dd id="person-name">&nbsp;</dd>
                            <dt class="caps prepend-top">E-Mail: </dt>
                            <dd id="person-email_primary">&nbsp;</dd>
	                        <dt class="caps prepend-top">Gender: </dt> 
	                        <dd id="person-gender">&nbsp;</dd>
                            <dt class="caps prepend-top">Nac: </dt> 
                            <dd id="person-nac_type">&nbsp;</dd>
                            <dd id="person-nac">&nbsp;</span></dd>
                            <dt class="caps prepend-top">Alternate E-Mail: </dt>
                            <dd id="person-email_alternate">&nbsp;</dd>
	                        <dt class="caps prepend-top">Phone Work: </dt> 
	                        <dd id="person-phone_work">&nbsp;</dd>
                            <dt class="caps prepend-top">Phone Home: </dt> 
                            <dd id="person-phone_home">&nbsp;</dd>
                            <dt class="caps prepend-top">Phone Mobile: </dt> 
                            <dd id="person-phone_mobile">&nbsp;</dd>
	                        <dt class="caps prepend-top">Address: </dt> 
	                        <dd id="person-address_line_1">&nbsp;</dd>
	                        <dd id="person-address_line_2">&nbsp;</dd>
	                        <dt class="caps prepend-top">Location: </dt> 
	                        <dd id="person-location">&nbsp;</dd>
	                        <dt class="caps prepend-top">Postcode: </dt> 
	                        <dd id="person-postcode">&nbsp;</dd>
	                        <dt class="caps prepend-top">Country: </dt> 
	                        <dd id="person-country_code">&nbsp;</dd>
	                    </dl>
                        <dl class="span-5 prepend-1 last">
                            <dt class="caps">Active: </dt> 
                        </dl>
                    </div>
                </div>
			<?php endif; ?>
			<div class="span-16 last">
	        <p><?php echo anchor('admin', 'Admin')?></p>
	        </div>
        </div> <!-- end content -->
        <?php $this->load->view('menu/admin')?>
    </div> <!-- end container -->
    <script type="text/javascript">
    $(document).ready(function() {
    	$('.box').corner("");

        if (location.hash != '') {
            var id = location.hash.substring(1);
            makeChanges(id);
        }
                
        $('.person-info').click(function(event) {
            event.preventDefault();
            var id = event.target.id.match(/^person-([0-9]+)$/);
            makeChanges(id[1]);
        });

        $('#name_autocomplete').simpleAutoComplete('people/ajax_acquery',{
            autoCompleteClassName: 'autocomplete',
            selectedClassName: 'sel',
            attrCallBack: 'rel',
            identifier: 'name'
            }, nameCallback);
    });

    function nameCallback(par) {
    	makeChanges(par[0]);
    }

    function makeChanges(id) {
        $.getJSON('/admin/people/ajax/view/'+id, function(data) {
            $.each(data, function(key, value) {
                $('#person-' + key).html(value);
            });

            $('#person-active').html((data.active)? 'Yes':'No');

            $('.person-info.selected').removeClass('selected');
            $('#person-'+id).addClass('selected');
            
            location.hash = id;
            $('#modify-link').attr('href', '<?php echo site_url(); ?>/profile/person/edit/' + id);
        });
    }
    </script>
</div> <!-- end main -->
<?php $this->load->view('footer/standard');?>
